1   package org.apache.tapestry5.internal.services.assets;
2   
3   import java.util.Map;
4   
5   import org.apache.tapestry5.services.assets.CompressionAnalyzer;
6   
7   public class CompressionAnalyzerImpl implements CompressionAnalyzer
8   {
9       private final Map<String, Boolean> configuration;
10  
11      public CompressionAnalyzerImpl(Map<String, Boolean> configuration)
12      {
13          this.configuration = configuration;
14      }
15  
16      public boolean isCompressable(String contentType)
17      {
18          if (contentType == null) {
19              throw new IllegalStateException("Content type provided to CompressionAnalyzer is null, which is not allowed.");
20          }
21  
22          int x = contentType.indexOf(';');
23  
24          String key = x < 0 ? contentType : contentType.substring(0, x);
25  
26          Boolean result = configuration.get(key);
27  
28          if (result != null) {
29              return result;
30          }
31  
32          // Now look for a wild card.
33  
34          x = contentType.indexOf('/');
35  
36          String wildKey = contentType.substring(0, x) + "/*";
37  
38          result = configuration.get(wildKey);
39  
40          return result == null ? true : result;
41      }
42  }